1 /************************************************************
2 * Copyright *
3 * Portions of this software are Copyright (c) 1993 - 2002, *
4 * Chad Z. Hower (Kudzu) and the Indy Pit Crew *
5 * - http://www.nevrona.com/Indy/ *
6 ************************************************************/
7 package org.indy;
8
9 /***
10 * IdURI
11 *
12 *@author owen
13 */
14 public class IdURI {
15 private String host = null;
16
17 /***
18 * Description of the Field
19 */
20 protected String port = null;
21
22 /***
23 * Description of the Field
24 */
25 protected String document = null;
26
27 /***
28 * Description of the Field
29 */
30 protected String path = null;
31
32 /***
33 * Description of the Field
34 */
35 protected String protocol = null;
36
37 /***
38 * Constructor for the IdURI object
39 */
40 protected IdURI() {
41 }
42
43 /***
44 * Gets the host attribute of the IdURI object
45 *
46 *@return The host value
47 */
48 public String getHost() {
49 return host;
50 }
51
52 /***
53 * Gets the port attribute of the IdURI object
54 *
55 *@return The port value
56 */
57 public String getPort() {
58 return port;
59 }
60
61 /***
62 * Gets the document attribute of the IdURI object
63 *
64 *@return The document value
65 */
66 public String getDocument() {
67 return document;
68 }
69
70 /***
71 * Gets the path attribute of the IdURI object
72 *
73 *@return The path value
74 */
75 public String getPath() {
76 return path;
77 }
78
79 /***
80 * Gets the protocol attribute of the IdURI object
81 *
82 *@return The protocol value
83 */
84 public String getProtocol() {
85 return protocol;
86 }
87
88 static String normalizePath(String path) {
89 char[] chars = new char[path.length()];
90
91 path.getChars(0, path.length() - 1, chars, 0);
92
93 for (int i = 0; i < chars.length; i++) {
94 switch (chars[i]) {
95 //remember '//'->'\' !
96 case '//':
97 chars[i] = '/';
98
99 break;
100
101 default:
102 break;
103 }
104 }
105
106 return new String(chars);
107 }
108
109 /***
110 * Description of the Method
111 *
112 *@param uri Description of the Parameter
113 *@return Description of the Return Value
114 */
115 public static IdURI pasreURI(String uri) {
116 uri = normalizePath(uri);
117
118 IdURI res = new IdURI();
119
120 int tokenPos = 0;
121
122 if ((tokenPos = uri.indexOf("://")) > -1) {
123 res.protocol = uri.substring(0, tokenPos);
124
125
126 //inc the tokenPosition
127 tokenPos += 3;
128 }
129 else {
130 tokenPos = 0;
131
132 //reset!
133 }
134
135 int portPos = 0;
136
137 int nextSlash = uri.indexOf("/", tokenPos);
138
139 if ((portPos = uri.indexOf(':', tokenPos)) > tokenPos) {
140 res.host = uri.substring(tokenPos, portPos);
141 res.port = uri.substring(portPos + 1, nextSlash);
142 }
143 else {
144 res.host = uri.substring(tokenPos, nextSlash);
145 }
146
147 tokenPos = nextSlash;
148 nextSlash = uri.indexOf('/', tokenPos);
149
150 int lastSlash = uri.lastIndexOf('/');
151
152 //if the next / is the last one, then we have no path
153 if (nextSlash != lastSlash) {
154 res.path = uri.substring(nextSlash + 1, lastSlash);
155 tokenPos = lastSlash;
156 }
157
158 char[] document = new char[uri.length() - tokenPos + 1];
159
160 res.document = uri.substring(tokenPos + 1);
161
162 return res;
163 }
164
165 /***
166 * The main program for the IdURI class
167 *
168 *@param args The command line arguments
169 */
170 public static void main(String[] args) {
171 IdURI test = pasreURI("/this/big/path/doc.html");
172
173 System.err.println(test.protocol);
174 System.err.println(test.host);
175 System.err.println(test.port);
176 System.err.println(test.path);
177 System.err.println(test.document);
178 }
179 }
This page was automatically generated by Maven